package com.stylefeng.sso.server.modular.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.stylefeng.roses.core.datascope.DataScope;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.api.AuthService;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.stylefeng.sso.server.auth.service.TokenAuthService;
import com.stylefeng.sso.server.modular.dto.UserDto;
import com.stylefeng.sso.server.modular.entity.SysUser;
import com.stylefeng.sso.server.modular.entity.User;
import com.stylefeng.sso.server.modular.mapper.UserMapper;
import com.stylefeng.sso.server.modular.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.functors.ConstantFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2018-12-07
 */
@Service
@Slf4j
public class UserService extends ServiceImpl<UserMapper, User> {

    @Autowired
    private TokenAuthService authService;

    /**
     * 通过账号获取用户
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:46
     */
    public User getByAccount(String account) {
        return this.baseMapper.getByAccount(account);
    }

    /**
     * 根据用户id获取用户信息
     */
    public LoginUser getUserLoginInfo(Integer userId) {
        User user = baseMapper.selectById(userId);
        if (user == null) {
            return null;
        }
        return authService.user(user.getAccount());
    }
}
